<template>
  <div>
    <el-row type="flex" justify="end">
      <!-- 年月下拉选择 -->
      <el-select v-model="currentYear" size="small" @change="onChangeDate">
        <el-option v-for="item in yearList" :key="item" :label="item" :value="item"></el-option>
      </el-select>
      <el-select v-model="currentMonth" size="small" @change="onChangeDate">
        <el-option v-for="item in 12" :key="item" :label="item" :value="item"></el-option>
      </el-select>
    </el-row>
    <!-- 时间日历表 -->
    <el-calendar v-model="currentDate">
      <!-- vue2.6之前写法 -->
      <!-- <template slot="dateCell" slot-scope="{date, data}"></template> -->
      <!-- vue2.6之后写法 -->
      <!-- v-slot:插槽名称="作用域插槽数据" -->
      <!-- #插槽名称="作用域插槽" -->
      <!-- v-slot:插槽名称="作用域插槽数据" -->
      <!-- #插槽名称="作用域插槽数据" -->
      <!-- 默认插槽名称完整写法v-slot:default="{row}" -->
      <!-- #default="{row}" -->
      <!-- <template #default="{row}"> -->
      <!-- <template v-slot:dateCell="{date, data}"></template> -->
      <template #dateCell="{ date }">
        <div class="date-content">
          <div class="text">
            {{ date | formatDate('D') }}
          </div>
          <div v-if="[6, 0].includes(date.getDay())" class="rest">休</div>
        </div>

        <!-- <span>{{ test(date) }}</span> -->
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  name: 'WorkCalendar',
  components: {},
  data() {
    const currentDate = new Date()
    const currentYear = currentDate.getFullYear()
    const currentMonth = currentDate.getMonth() + 1
    // const yearList = []
    // for (var i = -5; i <= 5; i++) {
    //   yearList.push(currentYear + i)
    // }//法二👇
    const yearList = Array.from(Array(11), (t, i) => currentYear + i - 5)
    return {
      currentYear,
      currentMonth,
      currentDate,
      yearList
    }
  },
  created() { },
  mounted() { },
  methods: {
    onChangeDate() {
      this.currentDate = new Date(this.currentYear + '-' + this.currentMonth)
    }
  }
}
</script>

<style lang="scss" scoped>
.el-select {
    width: 100px;
    margin-left: 15px;
}

::v-deep .el-calendar__header {
    display: none;
}
</style>
<style scoped>
::v-deeps .el-calendar-day {
    height: auto;
}

::v-deeps .el-calendar-table__row td,
::v-deeps .el-calendar-table tr td:first-child,
::v-deeps .el-calendar-table__row td.prev {
    border: none;
}

.date-content {
    height: 40px;
    text-align: center;
    line-height: 40px;
    font-size: 14px;
}

.date-content .rest {
    color: #fff;
    border-radius: 50%;
    background: pink;
    width: 20px;
    height: 20px;
    line-height: 20px;
    display: inline-block;
    font-size: 12px;
    margin-left: 10px;
}

.date-content .text {
    width: 20px;
    height: 20px;
    line-height: 20px;
    display: inline-block;

}

::v-deeps .el-calendar-table td.is-selected .text {
    background: #409eff;
    color: #fff;
    border-radius: 50%;
}

::v-deeps .el-calendar__header {
    display: none
}
</style>
